using System;
using System.Collections.Generic;
using System.Linq;
namespace TemplateWeb.Controllers
{
	#region using
	using System.Web.Mvc;
	using TemplateWeb.Models.ViewModels;
	using TemplateWeb.Models;
	using TemplateWeb.Models.Repositories;
	using TemplateWeb.Helpers;
	using System.Web.Security;
	#endregion
	public partial class AdminController: BaseController
	{
		public ActionResult SelectThietKeWeb()
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_THIETKEWEB
			};
			return View(CreateViewModel(data));
		}



		public ActionResult DeleteThietKeWeb(int id, int page = 1)
		{
			var result = _repThietKeWeb.Delete(id);
			var data = new DataTransferViewModel
			{
				InfoText = result ? "Item has been deleted" : "Cannot delete item!",
				EnumViewModelType = EnumViewModel.ADMIN_THIETKEWEB,
				CurrentPage = page
			};
			return View("SelectThietKeWeb", CreateViewModel(data));
		}

		public ActionResult DetailOfThietKeWeb(int id)
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_DETAILOF_THIETKEWEB,
				IntID = id
			};
			return View(CreateViewModel(data));
		}

		[ValidateInput(false)]
		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult UpdateThietKeWeb(FormCollection forms)
		{
			string id = forms.GetValues("ThietKeWeb_ID")[0];
			string gioithieu = forms.GetValues("ThietKeWeb_GioiThieu")[0];
			var thietkeweb = _repThietKeWeb.SelectByID(int.Parse(id));
			thietkeweb.GioiThieu = gioithieu;
			var result = _repThietKeWeb.Save();
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_DETAILOF_THIETKEWEB,
				IntID = int.Parse(id),
				InfoText = result ? "Item has been updated" : "Cannot update this item"
			};
			return View("DetailOfThietKeWeb", CreateViewModel(data));
		}


		[ValidateInput(false)]
		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult InsertThietKeWeb(FormCollection forms)
		{
			string gioithieu = forms.GetValues("ThietKeWeb_GioiThieu")[0];
			var newItem = new ThietKeWeb
			{
				GioiThieu = gioithieu
			};
			var result = _repThietKeWeb.Insert(newItem);
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_THIETKEWEB,
				InfoText = result ? "New item has been added" : "Cannot insert new item"
			};
			return View("SelectThietKeWeb", CreateViewModel(data));
		}


	}
}